/* global window */
import modelExtend from 'dva-model-extend'
import * as customerService from '../services/customer'
import {pageModel} from 'utils/model'

const {query} = customerService

export default modelExtend(pageModel, {
  namespace: 'bargainModel',

  effects: {

    * query ({payload = {}}, {call, put}) {
      const response = yield call(query, payload)
      const {data} = response
      if (data && response.code === 0) {
        yield put({
          type: 'querySuccess',
          payload: {
            list: data.records,
            pagination: {
              current: Number(payload.current) || 1,
              pageSize: Number(payload.size) || 10,
              total: data.total,
            },
          },
        })
      } else {
        throw response
      }
    },
  },
})
